Repository navigation
Conversation
…which DDC miscompiles into an infinite loop
… world direction with a return
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #2234.
What happens
Since Flutter 3.50.0 / Dart 3.14.0, in web debug builds,
CircleLayer,PolylineLayerandPolygonLayerthrow on paint and on hit test:The shapes are not drawn, and the error is thrown again on every repaint and pointer move over the map.
Release web builds, mobile and desktop are not affected. I hit this in our app right after upgrading from Flutter 3.47 to 3.50.
Root cause
It is a Dart compiler bug, not a flutter_map bug: dart-lang/sdk#64941. DDC (the web debug compiler) of Dart 3.14 drops the label of a
break label;placed inside aswitchwhose lastcaseis empty.workAcrossWorldshas exactly that shape:I compiled a copy of this function with
dartdevcfrom two SDKs (dartaotruntime bin/snapshots/dartdevc_aot.dart.snapshot --dart-sdk-summary=lib/_internal/ddc_outline.dill -o out.js probe.dart):Dart 3.10.9 (Flutter 3.38.10), correct:
Dart 3.14.0 (Flutter 3.50.0), wrong: the label is gone, so
breakonly leaves theswitchand the loop never ends, untilprotectInfiniteLoopthrows:The VM and dart2js compile the same code correctly, which is why only web debug builds break. This function is identical in 8.2.2, 8.3.2 and
master, so the regression comes from the SDK upgrade alone. I did not test Dart 3.11 to 3.13.The fix
The two world loops are now one local function called once per direction, which leaves with
return, so no label is needed. Theswitchstays exhaustive overWorldWorkControland the duplicated loop is gone. The behaviour is unchanged: same iteration order, same return values.I preferred this to adding an explicit
break;to the emptycase WorldWorkControl.visible:(the workaround mentioned in dart-lang/sdk#64941): that also works, but it looks redundant and could easily be removed later. A short comment links the Dart issue so the labeledbreakis not reintroduced.This was the only labeled
break/continueinlib/.Tests
New
test/layer/shared/feature_layer_utils_test.dartcoversworkAcrossWorldsdirectly: it stops in each direction at the first invisible world, keeps going while worlds are visible, returnstrueon a hit, and only works in the primary world when the CRS is not replicated.With Flutter 3.50.0 stable:
flutter test(VM)flutter test --platform chrome(DDC)master, new test fileInfinite loop going beyond 30 for world width 2048)master, existingtest/layer/circle_layer_test.dartInfinite loop going beyond 30 for world width 2097152)Full VM suite on this branch: 144 tests pass.
dart formatreports no change.Two tests of
network_image_provider_test.dart("Non-image response … exceptions enabled") fail with--platform chromeonmasteras well as on this branch; they are unrelated to this change.How to reproduce
Quickest, in this repository with Flutter 3.50.0:
In an app (no tile layer needed), run with
flutter run -d chrome:flutter_map: 8.3.2: grey screen, none of the three shapes is drawn, and the console fills withInfinite loop going beyond 30 for world width 524288(first thrown from_PolygonPainter.paint).git: {url: https://github.com/ZaraclaJ/flutter_map, ref: fix/ddc-labeled-break-infinite-loop-8.3.2}, the same commit on top ofv8.3.2): the polygon, the polyline and the circle are drawn, panning and zooming work, and the console stays empty.Notes